package com.ljx.recruitment.interview.controller;

import com.ljx.recruitment.common.domain.vo.resp.ApiResult;
import com.ljx.recruitment.common.domain.vo.resp.PageResp;
import com.ljx.recruitment.interview.domain.entity.Job;
import com.ljx.recruitment.interview.domain.entity.JobType;
import com.ljx.recruitment.interview.domain.vo.req.*;
import com.ljx.recruitment.interview.domain.vo.resp.*;
import com.ljx.recruitment.interview.service.JobLocationService;
import com.ljx.recruitment.interview.service.JobService;
import com.ljx.recruitment.interview.service.JobTypeService;
import com.ljx.recruitment.security.annotation.ApiPermission;
import com.ljx.recruitment.security.common.PermissionConstant;
import com.ljx.recruitment.user.domain.vo.resp.UserResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-11-01  23:46
 */
@Api(tags = "职位接口")
@RestController
@RequestMapping("/job")
public class JobController {

    @Autowired
    private JobService jobService;

    @Autowired
    private JobTypeService jobTypeService;

    @Autowired
    private JobLocationService jobLocationService;

    @ApiOperation("获取职位信息")
    @GetMapping("/info/{id}")
    public ApiResult<JobResp> getInfo(@PathVariable("id") Long jobId){
        return ApiResult.success(jobService.getInfo(jobId));
    }

    @ApiOperation("获取职位分页")
    @PostMapping("/page")
    public ApiResult<PageResp<JobResp>> getPage(@RequestBody JobPageReq req) {
        return ApiResult.success(jobService.getPage(req));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_SUBMIT})
    @ApiOperation("创建/修改职位")
    @PostMapping("/submit")
    public ApiResult<JobResp> submit(@Validated @RequestBody JobSubmitReq req){
        return ApiResult.success(jobService.submit(req));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_QUERY})
    @ApiOperation("获取职位类型分页")
    @GetMapping("/type/page")
    public ApiResult<PageResp<JobType>> getJobTypePage(JobPageReq req) {
        return ApiResult.success(jobTypeService.getJobTypePage(req));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_SUBMIT})
    @ApiOperation("创建/修改职位类型")
    @PostMapping("/type/submit")
    public ApiResult<JobTypeResp> submitJobType(@Validated @RequestBody JobTypeSubmitReq req){
        return ApiResult.success(jobTypeService.submitJobType(req));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_QUERY})
    @ApiOperation("获取职位分页（管理员）")
    @GetMapping("/admin/page")
    public ApiResult<PageResp<Job>> getPageByAdmin(JobPageReq req) {
        return ApiResult.success(jobService.getPageByAdmin(req));
    }

    @ApiPermission(permissions = {PermissionConstant.LOCATION_QUERY})
    @ApiOperation("获取工作地点分页")
    @GetMapping("/location/page")
    public ApiResult<PageResp<JobLocationResp>> getJobLocationPage(JobLocationPageReq req) {
        return ApiResult.success(jobLocationService.getJobLocationPage(req));
    }

    @ApiPermission(permissions = {PermissionConstant.LOCATION_SUBMIT})
    @ApiOperation("创建/修改工作地点类型")
    @PostMapping("/location/submit")
    public ApiResult<JobLocationResp> submitJobLocation(@Validated @RequestBody JobLocationSubmitReq req){
        return ApiResult.success(jobLocationService.submitJobLocation(req));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_QUERY})
    @ApiOperation("获取近年份")
    @GetMapping("/filter/year/list")
    public ApiResult<List<Integer>> getFilterYearList() {
        return ApiResult.success(jobService.getFilterYearList());
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_QUERY})
    @ApiOperation("获取职位已经录取的人员")
    @GetMapping("/offer/{jobId}/list")
    public ApiResult<List<UserResp>> getJobOfferList(@PathVariable("jobId") Long jobId) {
        return ApiResult.success(jobService.getJobOfferList(jobId));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_QUERY})
    @ApiOperation("获取职位面试流程")
    @GetMapping("/process/{jobId}/tree")
    public ApiResult<List<JobProcessTreeResp>> getJobProcessTreeList(@PathVariable("jobId") Long jobId) {
        return ApiResult.success(jobService.getJobProcessTreeList(jobId));
    }

    @ApiPermission(permissions = {PermissionConstant.JOB_QUERY})
    @ApiOperation("新增/删除职位面试流程")
    @PostMapping("/process/submit")
    public ApiResult<Void> submitProcess(@Valid @RequestBody JobProcessSubmitReq req) {
        jobService.submitProcess(req);
        return ApiResult.success();
    }

    @ApiOperation("获取主页秋招和社招的岗位")
    @GetMapping("/home/show")
    public ApiResult<JobHomeShowResp> getHomeJobShow() {
        return ApiResult.success(jobService.getHomeJobShow());
    }
}
